<template>
    <el-dialog title="选择供应商" :visible.sync="visible" width="1500px" append-to-body>

      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
        <el-form-item label="名称" prop="supplierName">
          <el-input
            v-model="queryParams.supplierName"
            placeholder="请输入名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
<!--        <el-form-item label="序号" prop="supplierNum">-->
<!--          <el-input-->
<!--            v-model="queryParams.supplierNum"-->
<!--            placeholder="请输入序号"-->
<!--            clearable-->
<!--            @keyup.enter.native="handleQuery"-->
<!--          />-->
<!--        </el-form-item>-->
        <el-form-item label="状态" prop="supplierState">
          <el-select v-model="queryParams.supplierState" placeholder="请选择状态" clearable>
            <el-option
              v-for="dict in dict.type.base_state"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="代号" prop="supplierCode">
          <el-input
            v-model="queryParams.supplierCode"
            placeholder="请输入代号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading"
                :data="SupplierList"
                :highlight-current-row = "true"
                @current-change="handleCurrentChange"
               >
<!--        <el-table-column type="selection" width="55" align="center" />-->
        <el-table-column label="供应商主键" align="center" prop="supplierId" />
        <el-table-column label="名称" width="200px" align="center" prop="supplierName" />
        <el-table-column label="联系人" align="center" prop="supplierLinkPerson" />
        <el-table-column label="电话" align="center" prop="supplierPhone" />
        <el-table-column label="序号" align="center" prop="supplierNum" />
        <el-table-column label="银行名称" align="center" prop="bankName" />
<!--        <el-table-column label="账号" align="center" prop="bankSn" />-->
<!--        <el-table-column label="地址" align="center" prop="supplierAddress" />-->
        <el-table-column label="状态" align="center" prop="supplierState">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.base_state" :value="scope.row.supplierState"/>
          </template>
        </el-table-column>
        <el-table-column label="代号" align="center" prop="supplierCode" />
<!--        <el-table-column label="是否入住" align="center" prop="supplierIsJoin" />-->
<!--        <el-table-column label="描述" align="center" prop="supplierInfo" />-->
        <el-table-column label="成立时间" align="center" prop="supplierFoundedDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.supplierFoundedDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="注册资金" align="center" prop="supplierRegisteredCapital" />

      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getModelList"
      />
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取 消</el-button>
        <el-button type="primary" @click="onSubmit">确 定</el-button>
      </span>
    </el-dialog>
</template>

<script>
import { listSupplier } from "@/api/webshop/Supplier";

export default {

  name: "SupplierModal",
  dicts: ['base_state'],
  data() {
    return {
      visible: false,

      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],

      // 总条数
      total: 0,
      // 供应商表格数据
      SupplierList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        supplierName: null,
        supplierNum: null,
        supplierState: null,
        supplierCode: null,
      },
      supplier: null
    }
  },
  methods: {
    init() {
      this.visible = true
      this.$nextTick(() => {
        this.getModelList()
      })
    },
    /** 查询供应商列表 */
    getModelList() {
      this.loading = true;
      listSupplier(this.queryParams).then(response => {
        this.SupplierList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getModelList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    handleCurrentChange(val){
      console.log(val)
      this.supplier = val
    },
    onSubmit(){
      // console.log(this.supplier)
      if(this.supplier==null){
        this.$message({
          message: '请选择供应商',
          type: 'warning'
        })
      }else{
        this.$emit('selectSupplier',this.supplier)
        this.visible = false
      }
    }

  }
}
</script>

